import D2Ext
from .Constants import *


class CGuiApplication(object):
    CHILDREN = []

    def __init__(self):
        pass

    @staticmethod
    def add(obj):
        CGuiApplication.CHILDREN.append(obj)

    @staticmethod
    def draw():
        for obj in CGuiApplication.CHILDREN:
            if obj.state == INVISIBLE:
                continue
            obj.draw()
            obj.draw_hover()

    @staticmethod
    def event(msg, param):
        # if D2Client.ptPlayerClient == 0:
        #     return False
        block_msgs = False
        for i in range(len(CGuiApplication.CHILDREN)-1, -1, -1):
            obj = CGuiApplication.CHILDREN[i]
            state = getattr(obj, 'state')
            if not state:
                continue
            if state == INVISIBLE:
                continue
            if not obj.event(msg, param):
                continue
            block_msgs = True
            break

        # block_msgs = False
        # for obj in CGuiApplication.CHILDREN:
        #     state = getattr(obj, 'state')
        #     if not state:
        #         continue
        #     if state == INVISIBLE:
        #         continue
        #     if not obj.event(msg, param):
        #         continue
        #     block_msgs = True
        #     break
        return block_msgs
